/**
 * @file file.c
 * @brief 
 * @author name
 * @version 1.0.1
 * @date 2023-04-14
 * 
 * @copyright Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version   <th>Author   <th>Description
 * <tr><td>2023-04-14 <td>1.0.1     <td>name     <td>首次创建
 * </table>
 */

/* includes ------------------------------------------------------------------*/
#include "var_mng.h"
#include "mcu_type.h"
/* macro/define --------------------------------------------------------------*/

/* typedef -------------------------------------------------------------------*/

/* local functions -----------------------------------------------------------*/

/* static variables ----------------------------------------------------------*/
static uint16_t var_buf[VAR_ID_MAX] = {0};
/* global variables ----------------------------------------------------------*/

/** ------------------------------------------------------------------------- *
  *                             Global function
 ** ------------------------------------------------------------------------- */

/**
 * @brief 变量初始化
 */
void var_init(void)
{

}

/**
 * @brief  设置某个全局变量值
 * @param  var_id : 变量地址
 * @param  set_val : 设置值
 */
uint8_t var_set_data(uint16_t var_id , uint16_t set_val)
{
    if(var_id >= VAR_ID_MAX)
       return FALSE;
	
    var_buf[var_id] = set_val;
	
    return TRUE;
}

uint8_t var_set_data_bit(uint16_t var_id ,uint16_t bit_pos , uint8_t bit_val)
{
    if(var_id >= VAR_ID_MAX)
       return FALSE;
	
    var_buf[var_id] = var_buf[var_id] & (~(1 << bit_pos));

    var_buf[var_id] |= ((bit_val & 0x01) << bit_pos);
	
    return TRUE;
}

/**
 * @brief  获取某个全局变量值值
 * @param  var_id : 变量地址
 * @return uint16_t 变量值
 */
uint16_t var_get_data(uint16_t var_id)
{
    if(var_id >= VAR_ID_MAX)
       return FALSE;
    
    return var_buf[var_id];
}

/** ------------------------------------------------------------------------- *
  *                              Local function
 ** ------------------------------------------------------------------------- */
 
/********** Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD *********/
